package org.come.Jpanel;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;

import javax.swing.ImageIcon;
import javax.swing.JLabel;
import javax.swing.JPanel;
import javax.swing.SwingConstants;

import org.come.Frame.ZhuFrame;
import org.come.bean.JadeorGoodstableBean;
import org.come.entity.Goodstable;
import org.come.mouslisten.RoleSuitMouslisten;
import org.come.until.GoodsListFromServerUntil;

import com.tool.btn.SwitchPageBtn;
import com.tool.btn.WorkshopBtn;
import com.tool.tcpimg.UIUtils;
import com.updateNew.MyIsif;



/**
 * @author Administrator 洗炼
 */
public class WashJpanel extends JPanel {

    private WorkshopBtn workshopBtn;// 洗炼按钮
    public static JLabel[] GoodsListLabel = new JLabel[21]; // 用来存放21个套装表格
    private static RoleSuitMouslisten[] suitMouslisten = new RoleSuitMouslisten[21]; // 21个套装表格监听
    private static JLabel labSet;// 套装
    private static JLabel[] labsx = new JLabel[4]; // 套装属性

    private SwitchPageBtn leftpageBtn,// 上一页按钮
            rightpageBtn;// 下一页按钮

    public static int page = 0;// 当前显示第几页装备
    private static JadeorGoodstableBean goodstableBean = new JadeorGoodstableBean();

    public WashJpanel() {
        if ("水墨UI".equals(MyIsif.getStyle())) {
            this.setPreferredSize(new Dimension(490, 428));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            // 套装
            labSet = new JLabel("", SwingConstants.CENTER);
            labSet.setBounds(300, 103, 54, 51);
            labSet.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = goodstableBean.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labSet);

            // 上一页按钮
            leftpageBtn = new SwitchPageBtn("skin/8100226/button/10.png", 1, 3);
            leftpageBtn.setBounds(120, 397, 18, 18);
            this.add(leftpageBtn);

            // 下一页按钮
            rightpageBtn = new SwitchPageBtn("skin/8100226/button/9.png", 1, 4);
            rightpageBtn.setBounds(145, 397, 18, 18);
            this.add(rightpageBtn);

            // 套装属性
            for (int i = 0; i < 4; i++) {
                labsx[i] = new JLabel("", SwingConstants.CENTER);
                labsx[i].setForeground(Color.white);
                labsx[i].setFont(UIUtils.TEXT_FONT1);
                if (i % 2 == 0) {
                    labsx[i].setBounds(234, 201 + (i / 2) * 27, 129, 21);
                } else {
                    labsx[i].setBounds(369, 201 + (i / 2) * 27, 50, 21);
                }
                this.add(labsx[i]);
            }

            // 放置套装
            for (int i = 0; i < 21; i++) {
                GoodsListLabel[i] = new JLabel();
                int row = i % 3;
                int col = i / 3;
                GoodsListLabel[i].setBounds(15 + row * 51, 37 + col * 51, 49, 49);
                suitMouslisten[i] = new RoleSuitMouslisten(i, this, null);
                GoodsListLabel[i].addMouseListener(suitMouslisten[i]);
                this.add(GoodsListLabel[i]);
            }

            // 洗炼按钮
            workshopBtn = new WorkshopBtn("skin/8100226/newbutton/B20.png", 1, UIUtils.COLOR_WHITE2, UIUtils.TEXT_HY16, "洗炼", 3);
            workshopBtn.setBounds(288, 315, 59, 24);
            this.add(workshopBtn);
        } else {
            this.setPreferredSize(new Dimension(490, 428));
            this.setLayout(null);
            this.setBackground(UIUtils.Color_BACK);

            // 套装
            labSet = new JLabel("", SwingConstants.CENTER);
            labSet.setBounds(300, 103, 54, 51);
            labSet.addMouseListener(new MouseListener() {
                @Override
                public void mouseReleased(MouseEvent e) {
                }

                @Override
                public void mousePressed(MouseEvent e) {
                }

                @Override
                public void mouseExited(MouseEvent e) {
                    ZhuFrame.getZhuJpanel().cleargoodtext();
                }

                @Override
                public void mouseEntered(MouseEvent e) {
                    Goodstable goodstable = goodstableBean.getGoodstable();
                    if (goodstable == null) {
                        return;
                    }
                    ZhuFrame.getZhuJpanel().creatgoodtext(goodstable);
                }

                @Override
                public void mouseClicked(MouseEvent e) {
                }
            });
            this.add(labSet);

            // 上一页按钮
            leftpageBtn = new SwitchPageBtn("inkImg/hongmu/2/30_png.button.btn_8.png", 1, 3);
            leftpageBtn.setBounds(120, 397, 18, 18);
            this.add(leftpageBtn);

            // 下一页按钮
            rightpageBtn = new SwitchPageBtn("inkImg/hongmu/2/36_png.button.btn_7.png", 1, 4);
            rightpageBtn.setBounds(145, 397, 18, 18);
            this.add(rightpageBtn);

            // 套装属性
            for (int i = 0; i < 4; i++) {
                labsx[i] = new JLabel("", SwingConstants.CENTER);
                labsx[i].setForeground(Color.white);
                labsx[i].setFont(UIUtils.TEXT_FONT1);
                if (i % 2 == 0) {
                    labsx[i].setBounds(234, 201 + (i / 2) * 27, 129, 21);
                } else {
                    labsx[i].setBounds(369, 201 + (i / 2) * 27, 50, 21);
                }
                this.add(labsx[i]);
            }

            // 放置套装
            for (int i = 0; i < 21; i++) {
                GoodsListLabel[i] = new JLabel();
                int row = i % 3;
                int col = i / 3;
                GoodsListLabel[i].setBounds(15 + row * 51, 37 + col * 51, 49, 49);
                suitMouslisten[i] = new RoleSuitMouslisten(i, this, null);
                GoodsListLabel[i].addMouseListener(suitMouslisten[i]);
                this.add(GoodsListLabel[i]);
            }

            // 洗炼按钮
            workshopBtn = new WorkshopBtn("inkImg/hongmu/1/w50.png", 1, UIUtils.COLOR_BTNPUTONG2, UIUtils.TEXT_HY16, "洗 炼", 3);
            workshopBtn.setBounds(288, 291, 60, 26);
            this.add(workshopBtn);
        }

    }

    private ImageIcon icon;

    @Override
    protected void paintComponent(Graphics g) {
        super.paintComponent(g);
        if ("水墨UI".equals(MyIsif.getStyle())) {
            if (icon == null) {
                icon = new ImageIcon("inkImg/newbackground/B243.png");
            }
            // 背景
            g.drawImage(icon.getImage(), 0, 0, 490, 428, this);
            // 画套装信息
            GoodsListFromServerUntil.drawRoleSuit(g, 15, 37, page, 21);
        } else {
            if (this.icon == null) {
                this.icon = new ImageIcon("inkImg/hongmu/2/setsynthesis_xl.png");
            }
            g.drawImage(this.icon.getImage(), 0, 0, 490, 428, this);
            GoodsListFromServerUntil.drawRoleSuit(g, 15, 37, page, 21);
        }
    }

    /**
     * 清空界面
     */
    public static void clearInterface() {
        goodstableBean.setGoodstable(null);
        labSet.setIcon(null);
        for (int i = 0; i < 4; i++) {
            labsx[i].setText("");
        }
    }

    public WorkshopBtn getWorkshopBtn() {
        return workshopBtn;
    }

    public void setWorkshopBtn(WorkshopBtn workshopBtn) {
        this.workshopBtn = workshopBtn;
    }

    public static RoleSuitMouslisten[] getSuitMouslisten() {
        return suitMouslisten;
    }

    public static void setSuitMouslisten(RoleSuitMouslisten[] suitMouslisten) {
        WashJpanel.suitMouslisten = suitMouslisten;
    }

    public static JLabel getLabSet() {
        return labSet;
    }

    public static void setLabSet(JLabel labSet) {
        WashJpanel.labSet = labSet;
    }

    public static JadeorGoodstableBean getGoodstableBean() {
        return goodstableBean;
    }

    public static void setGoodstableBean(JadeorGoodstableBean goodstableBean) {
        WashJpanel.goodstableBean = goodstableBean;
    }

    public static JLabel[] getLabsx() {
        return labsx;
    }

    public static void setLabsx(JLabel[] labsx) {
        WashJpanel.labsx = labsx;
    }
}
